import os
from dataclasses import dataclass
import queue

from datetime import datetime

from pandas import DataFrame

current_file_path = os.path.abspath(__file__)
current_directory_path = os.path.dirname(current_file_path)
db_file_name = "sensor_data.db"
DB_Path = os.path.join(current_directory_path, "db", db_file_name)

# 数据表中的列名

# 获取数据的列名
Sensor_Data_Col = ["sensor_code", "d_date", "d_time", "acc_x", "acc_y", "acc_z", "gyro_x", "gyro_y",
                   "gyro_z", "mag_x", "mag_y", "mag_z", "angle_x", "angle_y", "angle_z", "temp", "bat",
                   "rss",
                   "sensor_id"]
# 计算的列名
Calculate_col = ["sensor_id", "acc_x", "acc_y", "acc_z", "gyro_x", "gyro_y", "gyro_z",
                 "mag_x", "mag_y", "mag_z", "angle_x", "angle_y", "angle_z", "temp", "bat", "rss"]

Location = ["A端", "B端", "底座A侧", "底座B侧"]
Direction = ["x", "y"]

Search_Sensor_State = False  # 传感器搜索状态


@dataclass
class Product:
    id: int = 0
    label: str = ""
    name: str = ""
    create_date = datetime.now()


@dataclass
class Sensor:
    id: int = 0
    sensor_code: str = ""
    location: str = Location[0]
    direction: str = Direction[0]
    product_id: int = 0
    agree_base = {"x": 0, "y": 0}


class ProjectInfo:
    sensor_code_list: list = []  # 传感器编码的列表
    sensor_count = 0
    a_sensor_code_list = []
    b_sensor_code_list = []
    sensor_info_dict: dict = dict()  # 传感器信息字典,传感器的编号是key
    sensor_base_info_df = DataFrame()  # 传感器记录数据的初始值
    product = Product()  # 产品信息

    Sensor_data_Send_state = False  # 传感器发送数据的状态
    Sensor_data_Record_state = False  # 传感器记录数据的状态
    test_state = False
    Base_Angle_Info = dict()
    line_chart_index = 0  # 折线图的数据数量（x轴坐标）

    # 线程队列
    sensor_raw_data_queue = queue.Queue()  # 记录传感器的原始值
    sensor_data_queue = queue.Queue()  # 存放解析后的传感器数据
    sensor_data_mean_queue = queue.Queue()  # 存放传感器数据的平均值
    sensor_recorded_data_queue = queue.Queue()  # 存储存入数据库中的传感器平均值的数据

    location_list = Location
    direction_list = Direction

    # 折线图点数据
    a_agree_line_chart_list = []
    b_agree_line_chart_list = []
    total_line_chart_list = []
    acc_a_x_line_chart_list = []
    acc_b_x_line_chart_list = []
    acc_a_y_line_chart_list = []
    acc_b_y_line_chart_list = []
    acc_a_z_line_chart_list = []
    acc_b_z_line_chart_list = []

